import React,{Component} from 'react'
import {connect} from 'react-redux'
import {incrment} from './store/actionCreators'
class Index extends Component{
    constructor(props){
        super(props)
        this.state = {
            total: 60
        }
    }
    render(){
        return <div>      
              <h1>状态：{this.props.total}</h1>
              <button onClick={this.props.incrment}>更新</button>
            </div>
    }
}

const mapStateToProps = state => { // state就是仓库store数据
    //  console.log(state.toJS().articles)
      return { // 组件中通过 this.props.键 来获取数据
          // 键: state.数据
          total: state.toJS().articles.total
      }
  }
  const mapDispatchToProps= dispatch => {
      return { // 组件中通过this.props.键()
          // 键: index => dispatch(incrment(index))   // 注：dispatch中传递的是action
          incrment: () => dispatch(incrment())
      }
  }
  export default connect(mapStateToProps, mapDispatchToProps)(Index)